package com.ww.scm.repository.pub;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.ww.core.orm.hibernate.HibernateDao;
import com.ww.scm.entity.pub.Sequence;
import com.ww.scm.valueObject.SequenceVo;


//Spring Bean的标识.
@Component
public class SequenceRepository extends HibernateDao<Sequence, String>{
	
	private final static Map<String,SequenceVo> sequenceCache=new HashMap<String,SequenceVo>();
	
	private final static int POOL_SIZE=10;
	
	public synchronized int getNextSequence(String key){
		if (sequenceCache.containsKey(key)==false){
			SequenceVo sequenceVo=new SequenceVo(key,POOL_SIZE,this);
			sequenceCache.put(key, sequenceVo);
		}
		SequenceVo sequenceVo=sequenceCache.get(key);
		return sequenceVo.getNextValue(this);
	}

}
